package cn.itcast.nems.config;

import lombok.Data;
import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * <p>
 * Redisson  初始化 Config
 * </p>
 *
 * @author zhouwei
 * @since 2023/10/18 2:17 PM
 **/
@Configuration
@ConfigurationProperties(prefix = "spring.data.redis")
@Data
public class RedissonConfig {
 
    private String host;
    private int port;
    private String password;
    private int  database;
    /**
     * 实例化 redissonClient
     * @return RedissonClient
     **/
    @Bean
    public RedissonClient redissonClient() {
        Config config = new Config();
        config.useSingleServer().setAddress("redis://" + host + ":" + port);
        config.useSingleServer().setPassword(password) ;
        config.useSingleServer().setDatabase(database) ;
        return Redisson.create(config);
    }

}
